package com.example.mq;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

public class RocketAsyncProducer {
    public static void main(String[] args) throws  InterruptedException{
        DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
//        producer.setNamesrvAddr("10.13.8.234:8100;10.13.8.233:8100");
        producer.setNamesrvAddr("10.13.10.251:8100;10.13.10.174:8100");
        producer.setUseTLS(true);
        try {
            producer.start();
            Message msg = new Message("test1", "TagName", "OrderID", "Message".getBytes(RemotingHelper.DEFAULT_CHARSET));
            producer.send(msg, new SendCallback() {
                @Override
                public void onSuccess(SendResult result) {
                    System.out.println("send message success. msgId="+ result.getMsgId());
                }

                @Override
                public void onException(Throwable throwable) {
                    System.out.println("send message failed.");
                    throwable.printStackTrace();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
        Thread.sleep(2000);
        producer.shutdown();
    }
}
